package com.cheyun.netsalev3.viewmodel

import android.content.Intent
import android.view.View
import androidx.lifecycle.Transformations
import com.cheyun.netsalev3.bean.dm.DmClueList
import com.cheyun.netsalev3.repository.DmPageRepository
import com.cheyun.netsalev3.view.dm.detail.DmDetailsActivity

class DmListViewModel(var repository: DmPageRepository) : BaseViewModel() {
     var items= repository.loadAndroidData()

    val networkState = Transformations.switchMap(items) { repository.networkState }!!
    val total = Transformations.switchMap(items) { repository.total }!!

    fun onClickItem(view: View, item: DmClueList) {
        var intent = Intent(view.context, DmDetailsActivity::class.java)
        intent.putExtra("id",item.id.toString())
        view.context.startActivity(intent)
    }

    fun refresh(){
        repository.dataSourceFactory.sourceLiveData.value?.invalidate()
    }
}